<template>
  <div class="patient-info-overlay" v-if="visible">
    <div class="overlay-header">
      <span>患者信息</span>
      <i class="el-icon-close" @click="$emit('close')"></i>
    </div>
    <div class="overlay-content">
      <div class="info-row">
        <span class="info-label">姓名:</span>
        <span class="info-value">{{ patientName }}</span>
      </div>
      <div class="info-row" v-if="patientInfo">
        <span class="info-label">性别:</span>
        <span class="info-value">{{ patientInfo.sex || '未知' }}</span>
      </div>
      <div class="info-row" v-if="patientInfo">
        <span class="info-label">出生日期:</span>
        <span class="info-value">{{ formatBirthDate(patientInfo.birthDate) || '未知' }}</span>
      </div>
      <div class="info-row" v-if="studyInfo">
        <span class="info-label">检查日期:</span>
        <span class="info-value">{{ formatStudyDate(studyInfo.studyDate) }}</span>
      </div>
      <div class="info-row" v-if="studyInfo">
        <span class="info-label">检查描述:</span>
        <span class="info-value">{{ studyInfo.studyDescription || '无描述' }}</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'PatientInfoOverlay',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    patientName: {
      type: String,
      default: '未知患者'
    },
    patientInfo: {
      type: Object,
      default: null
    },
    studyInfo: {
      type: Object,
      default: null
    }
  },
  methods: {
    formatBirthDate(dateString) {
      if (!dateString) return '未知';
      // 格式化日期: YYYYMMDD -> YYYY-MM-DD
      return dateString.replace(/(\d{4})(\d{2})(\d{2})/, '$1-$2-$3');
    },
    formatStudyDate(dateString) {
      if (!dateString) return '未知';
      // 格式化日期: YYYYMMDD -> YYYY-MM-DD
      return dateString.replace(/(\d{4})(\d{2})(\d{2})/, '$1-$2-$3');
    }
  }
}
</script>

<style scoped>
.patient-info-overlay {
  position: absolute;
  top: 10px;
  left: 10px;
  background-color: rgba(30, 37, 56, 0.9);
  border-radius: 6px;
  width: 300px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  z-index: 100;
  overflow: hidden;
  backdrop-filter: blur(5px);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.overlay-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 15px;
  background-color: #409EFF;
  color: white;
}

.overlay-header i {
  cursor: pointer;
  transition: transform 0.2s ease;
}

.overlay-header i:hover {
  transform: scale(1.1);
}

.overlay-content {
  padding: 15px;
}

.info-row {
  margin-bottom: 8px;
  display: flex;
}

.info-label {
  width: 80px;
  color: rgba(255, 255, 255, 0.7);
}

.info-value {
  flex: 1;
  font-weight: 500;
  color: #fff;
}
</style>
